﻿using System;
using System.Linq;
using System.Web.UI;
using System.Web.DynamicData;
using NotAClue.Web.DynamicData;
using NotAClue;

namespace DD_Extensions
{
    public partial class Enumeration : System.Web.DynamicData.FieldTemplateUserControl
    {
        public override Control DataControl
        {
            get { return Literal1; }
        }

        public string EnumFieldValueString
        {
            get
            {
                if (FieldValue == null)
                    return FieldValueString;

                Type enumType = Column.GetEnumType();

                if (enumType != null)
                {
                    object enumValue = Enum.ToObject(enumType, FieldValue);
                    return FormatFieldValue(enumValue);
                    //return enumValue.ToString().ToTitleFromPascal();
                }

                return FieldValueString;
            }
        }

        protected void Page_Init(object sender, EventArgs e)
        {
            // add tool-tip
            this.SetupTip();

            // add CSS from meta data
            this.ApplyCss();
        }
    }
}